<!DOCTYPE HTML>
<html>
<head>
    <title>Error</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body>
<form id="form1" name="form1"  method="post" action='/getdata/addBannerGoodsRelation' enctype="multipart/form-data">
    <span style="width:80px;display:inline-block;">商品类型：</span>

    <input id="typeName" name="typeName" class="mini-combobox" required="true" style="width:155px;"  data="typeData"/>
    <br/>
    <br/>
    <span style="width:80px;display:inline-block;">商品：</span>
    <input id="btnEdit1" required="true" class="mini-buttonedit" onbuttonclick="onButtonEdit" name="goodsId" textName="goodsName"/>
    <br/><br/>





</form>

<div style="padding-top: 10px;text-align: center">
    <a class="mini-button " iconCls="icon-ok" onclick="addBannerGoodsRelation()">确定</a>
    <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
</div>
</body>
<script>
    var typeData = [{ id: 0, text:'积分商品' },{ id: 1, text: '普通商品' }];

    var shopGoodTypeId = '<%=objectId %>'
     // classType=[{id:1,text:"海报分类管理"},{id:2,text:"标题分类管理"},{id:3,text:"商品分类管理"}]
    mini.parse();
    function addBannerGoodsRelation() {
        var data = new mini.Form("#form1").getData();
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) {
            alert("请正确填写数据")
            return
        };
        data.shopGoodTypeId = shopGoodTypeId
        console.log(data)
        $.ajax({
            type: "POST",
            url: "/getdata/banner/addBannerGoodsRelation",
            data:data,
            success: function (result) {
                if(result==10000){
                    alert("添加成功");
                    CloseWindow("save");
                }else{
                    alert("更改失败");
                    CloseWindow("save");
                }
            }
        })
    }





    //    关闭窗口
    function CloseWindow(action) {
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }
    function onOk(e) {
        SaveData();
    }
    function onCancel(e) {
        CloseWindow("cancel");
    }


    function onButtonEdit(e) {
       let id =  mini.get('typeName').getValue()
        console.log(id)
        if (id == 1){
            var btnEdit = this;
            mini.open({
                url: "/editor/shopGoodsChoice",
                title: "普通商品列表",
                width: 1100,
                height: 450,
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);    //必须
                        if (data) {
                            btnEdit.setText(data.text);
                            btnEdit.setValue(data.id);
                        }
                    }else {
                        btnEdit.setText("");
                    }

                }
            });
        }else{
            var btnEdit = this;

            mini.open({
                url: "/editor/scoreShopGoodsChoice",
                title: "积分商城商品列表",
                width: 1100,
                height: 450,
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        console.log(data)
                        data = mini.clone(data);    //必须
                        if (data) {
                            btnEdit.setText(data.text);
                            btnEdit.setValue(data.id);
                        }
                    }else {
                        btnEdit.setText("");
                    }

                }
            });
        }


    }


</script>
</html>